package com.example.demo.common;

import com.example.demo.entity.Time;
import org.springframework.context.annotation.Configuration;

import java.time.Duration;
import java.time.LocalDateTime;
import java.util.concurrent.TimeUnit;

/**
 * Created with IntelliJ IDEA.
 * Description: 博客发布时间公共类
 */
public class ArticleTimeUtil {

    public static Duration getTime(Time time) {
        // 获取当前时区的当前时间
        LocalDateTime nowTime = LocalDateTime.now();
        // 将用户传过来的时间对象进行包装
        LocalDateTime userTime =
                LocalDateTime.of(time.getYear(), time.getMonth(), time.getDay(), time.getHour(), time.getMinute(), time.getSecond());
        // 获取规定时间和当前时间之间的差值并包装为 Duration 类
        return Duration.between(nowTime, userTime);

    }
}
